package main

import (
	"fmt"
	"strings"
)

//闭包练习
func main() {
	fmt.Println("请传入文件名")
	var fileName string
	fmt.Scan(&fileName)

	fmt.Println("输入的文件名", fileName)
	//先引用生成闭包
	resFileName := makeSuffix(".jpg")
	//然后过滤参数
	fmt.Println("最后的文件名称是", resFileName(fileName))
}

func makeSuffix(suffix string) func(filename string) string {
	return func(filename string) string {
		if !strings.HasSuffix(filename, suffix) {
			return filename + suffix
		}
		return filename
	}
}
